package com.atguigu.gulimall.seckill.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.seckill.service.SeckillService;
import com.atguigu.gulimall.seckill.to.SkuInfoRedisTo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class SeckillController {

    @Resource
    SeckillService seckillService;

    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus(){
        List<SkuInfoRedisTo> vos = seckillService.getCurrentSeckillSkus();
        return R.ok().put("data",vos);
    }

    @GetMapping("/sku/seckill/{skuId}")
    public R getSkuSeckillInfo(@PathVariable("skuId") Long skuId){
        SkuInfoRedisTo to = seckillService.getSkuSeckillInfo(skuId);
        return R.ok().put("data",to);
    }

    @GetMapping("/kill")
    public R kill(@RequestParam("killId") String killId,@RequestParam("key") String key,@RequestParam("num") Integer num){
        String result = seckillService.kill(killId,key,num);
        return R.ok().put("data",result);
    }
}
